package com.heima.article.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author itlxc
 * @since 2024-07-28
 */
@Service
@Slf4j
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    /**
     * 修改文章配置
     * @param map
     */
    @Override
    public void updateByMap(Map<String, Object> map) {
        //0 下架 1 上架
        Object enable = map.get("enable");
        boolean isDown = true;
        if (ObjectUtil.equal(enable, 1)) {
            isDown = false;
        }
        //修改文章配置
        this.lambdaUpdate().set(ApArticleConfig::getIsDown, isDown)
                            .eq(ApArticleConfig::getArticleId, map.get("articleId"))
                            .update();
    }

}
